package duoxiancheng;

/**
 * @Author Zhouchb
 * @Create 2021-10-2021/10/23 :16:27
 * @Description
 */
public class MyThread extends Thread{
    private static int titck = 100; //100张票 三个线程来抢
    static boolean flag = true;
    @Override
    public void run() {
       /*for (;titck>0;titck--){
          // if (titck%2==0)
           System.out.println(Thread.currentThread().getName()+titck);
       }*/
        while (flag){
        show();
        }
    }
    public static synchronized void show(){
        if (titck>0){
            System.out.println(Thread.currentThread().getName()+titck);
            titck--;
        }
        if (titck<=0){
            flag = false;
        }
    }
}
class MyThreadTest {
    public static void main(String[] args) {
        MyThread myThread1 = new MyThread();
        MyThread myThread2 = new MyThread();
        MyThread myThread3 = new MyThread();
        myThread1.setPriority(Thread.MAX_PRIORITY); //设置线程优先级
        myThread1.setName("线程一：");
        myThread2.setName("线程二：");
        myThread3.setName("线程三：");
        myThread1.start();
        myThread2.start();
        myThread3.start();

    }
}